/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package towerz.game;

import java.io.IOException;
import javax.microedition.lcdui.Graphics;
import towerz.system.Utilities;

/**
 *
 * @author LegACy
 */
public class Cursor {
	//Cursor states
	public static final int NONE	= 0;
	public static final int	OKAY	= 1;
	public static final int	VALID	= 2;
	public static final int ERROR	= 3;

	public Cursor(int x, int y) {
		//Initialize
		m_TileX = x;
		m_TileY = y;
		m_State = Cursor.NONE;
		
		//Create sprite
		try {
			m_Sprite = new Sprite(Utilities.TILECURSOR_IMAGE, 1, 4);
		} catch (IOException ex) {}
	}

	public int getTileX() {
		return m_TileX;
	}

	public int getTileY() {
		return m_TileY;
	}

	public void setTilePosition(int x, int y) {
		//Set position
		m_TileX = x;
		m_TileY = y;
	}

	public void setState(int state) {
		m_State = state;
        m_Sprite.setFrame(state);
	}

	public void draw(Graphics g, int startX, int startY, int endX, int endY, int offsetX, int offsetY) {
		//Ensure its drawn
		if (startX > m_TileX || startY > m_TileY) return;
		if (endX <= m_TileX || endY <= m_TileY) return;

		//Set position and draw
		m_Sprite.setTilePosition(m_TileX - startX, m_TileY - startY, offsetX, offsetY);
		m_Sprite.draw(g);
	}

	//Members
	protected int m_TileX;
	protected int m_TileY;
	protected int m_State;
	protected Sprite m_Sprite;
}
